package com.lgx.mall.business.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.lgx.common.basic.dao.GeneralDao;
import com.lgx.mall.business.dao.IScoreGiftRecordsDao;
import com.lgx.mall.business.entity.ScoreGiftRecords;

@Component
public class ScoreGiftRecordsDao  extends GeneralDao implements IScoreGiftRecordsDao{
	
	protected Logger log = Logger.getLogger(this.getClass());

	/**
	 * 根据id查找
	 */
	@Override
	public ScoreGiftRecords findSGRsById(Long id){
		 return this.getHibernateTemplate().get(ScoreGiftRecords.class, id);
	}

	/**
	 * 删除
	 */
	@Override
	public void deleteSGRs(ScoreGiftRecords scoreGiftRecords) throws Exception{
		log.info("[删除订单]:"+scoreGiftRecords.getId());
		this.getHibernateTemplate().delete(scoreGiftRecords);
	}

	/**
	 * 修改
	 */
	@Override
	public void updateSGRs(ScoreGiftRecords scoreGiftRecords) throws Exception{
		log.info("[修改订单]:"+scoreGiftRecords.getId());
		this.getHibernateTemplate().update(scoreGiftRecords);
	}

	/**
	 * 创建
	 */
	@Override
	public ScoreGiftRecords createOrder(ScoreGiftRecords scoreGiftRecords) throws Exception{
		this.getHibernateTemplate().save(scoreGiftRecords);
		log.info("[创建订单]:"+scoreGiftRecords.getId());
		return scoreGiftRecords;
	}

	/**
	 * 根据发起人id查找
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ScoreGiftRecords> findSGRs(Long fromId) throws Exception{
		String sql = "from ScoreGiftRecords s where s.fromId = "+fromId+" order by s.id desc";
		return this.getHibernateTemplate().find(sql);
	}

}
